package com.demo;

public class merge {
    public static void main(String[] args) {
        int[] nums1 = {1,2,3,0,0,0};
        int[] nums2 = {2,5,8};
        int m=3;
        int n=3;
        int[] result = new int[m+n];
        int i = 0;
        int j = 0;
        int count = 0;
        while (i<m && j<n){
            if ( nums1[i]<=nums2[j]) {
                result[count++]=nums1[i];
                i++;
            }else{
                result[count++]=nums2[j];
                j++;
            }
        }
        while (i<m){
            result[count++]=nums1[i++];
        }
        while (j<n){
            result[count++]=nums2[j++];
        }
        for (int k = 0; k <m+n ; k++) {
            nums1[k]=result[k];
        }
        for (int a : nums1 ){
            System.out.print(a+" ");
       }
    }
}
